package main

import "fmt"

func maxProfit(prices []int) int {
	const INT_MAX = int(^uint(0) >> 1)
	max := 0
	minN := INT_MAX
	for i := 0; i < len(prices); i++ {
		if minN > prices[i] {
			minN = prices[i]
		} else if max < prices[i]-minN {
			max = prices[i] - minN
		}
	}
	return max
	//max := 0
	//for i:=0;i<len(prices);i++  {
	//	for j:=i+1;j<len(prices) ;j++  {
	//		if prices[i] < prices[j] && max < prices[j]-prices[i] {
	//			max = prices[j]-prices[i]
	//		}
	//	}
	//}
	//return max
}
func main() {
	arr := []int{7, 1, 5, 3, 6, 4}
	fmt.Println(maxProfit(arr))
}
